/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import React, { useEffect } from "react";
import { Button } from "antd";
import StandardTable from "@/components/StandardTable";
import { debounce } from "lodash";
import { connect } from "dva";

const defaultPagination = {
  pageSize: 5,
  page: 1,
};
const ExportList = props => {
  const { orderExportList, dispatch } = props;

  useEffect(
    () => {
      dispatch({ type: "orderDetails/getOrderExportList", payload: { ...defaultPagination } });
    },
    [dispatch]
  );

  const handleExportFile = debounce(
    file_path => {
      file_path && (location.href = file_path);
    },
    500,
    {
      leading: true,
      trailing: false,
    }
  );

  const columns = [
    { dataIndex: "file_name", title: "文件名" },
    { dataIndex: "add_time", title: "任务添加时间" },
    {
      title: "操作",
      dataIndex: "file_path",
      render(url, item) {
        return (
          <Button
            type="primary"
            disabled={item.is_finish == 0}
            onClick={() => handleExportFile(url)}
          >
            导出
          </Button>
        );
      },
    },
  ];

  return <StandardTable rowKey="id" columns={columns} data={orderExportList} />;
};

export default connect(({ orderDetails }) => ({ orderExportList: orderDetails.orderExportList }))(
  ExportList
);
